package cn.sh.library.mgts.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value="页码对象模型")
public class Pager implements Serializable {

	private static final long serialVersionUID = 2041867004894668270L;
//	private Logger logger = Logger.getLogger(Pager.class);
	private static Logger logger = LoggerFactory.getLogger(Pager.class);

	/** 开始索引 */
	Integer startIndex = 0;
	/** 分页大小 */
	@ApiModelProperty(value="分页大小", required=false)
	Integer pageSize = 10;
	/** 当前页码 */
	@ApiModelProperty(value="当前页码", required=false)
	Integer pageth = 1;
	/** 总页码数 */
	Integer pageCount = 0;
	/** 总记录数 */
	Long rowCount = 0L;	
	
	Long took = 0L;
	
	public Long getTook() {
		return took;
	}

	public void setTook(Long took) {
		this.took = took;
	}

	public Pager() {}

	public Pager(Integer startIndex, Integer pageSize) {
		setStartIndex(startIndex);
		setPageSize(pageSize);
	}

	public void calcPageCount(Long rowCount) {
		setRowCount(rowCount);
		if (pageSize != 0) {
			pageCount = rowCount.intValue() / pageSize;
			if (pageCount * pageSize < rowCount) {
				pageCount++;
			}
		}
		if (rowCount == 0) {
			pageth = 1;
		}
	}
	
	public Integer getPageth() {return pageth;}
	public void setPageth(Integer pageth) {
		this.pageth = pageth;
		Integer ps = getPageSize();
		startIndex = (getPageth() - 1) * ps;
	}

	public Integer getPageCount() {return pageCount;}
	public void setPageCount(Integer pageCount) {this.pageCount = pageCount;}
	
	public Integer getPageSize() {return pageSize;}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
		setPageth(getPageth());
	}

	public Long getRowCount() {return rowCount;}
	public void setRowCount(Long rowCount) {this.rowCount = rowCount;}

	
	public Integer getStartIndex() {return startIndex;}
	public void setStartIndex(Integer startIndex) {this.startIndex = startIndex;}

}
